package manager

import (
	"hermestrans/internal/dataccess"
	config "hermestrans/internal/portal/config"
	"hermestrans/internal/portal/schema"

	"github.com/pkg/errors"
)

type MysqlMgr struct {
	*dataccess.Mysql
}

func InitMysqlManager(conf *config.Config) (*MysqlMgr, error) {
	var (
		err      error
		mysqlMgr *dataccess.Mysql
	)
	mysqlConf := conf.MysqlConfig
	mysqlMgr, err = dataccess.NewMysql(mysqlConf.Mysql, mysqlConf.Gorm,
		mysqlConf.MaxIdleConns, mysqlConf.MaxOpenConns, mysqlConf.ConnMaxIdleTime)
	if err != nil {
		return nil, errors.WithMessage(err, "Init table fail")
	}

	ret := &MysqlMgr{
		mysqlMgr,
	}
	return ret, nil
}

func (m *MysqlMgr) GetAdminUsers(nickname string, created_time string) {

}

func (m *MysqlMgr) GetAdminUser(conditions map[string]interface{}) (adminUser schema.AdminUsers, err error) {
	err = m.MysqlDB.Where(conditions).First(&adminUser).Error
	return
}
